import torch

features = torch.load("features.pth")
qf = features["qf"] # query的几张图片的features
ql = features["ql"] # query的几张图片的labels
gf = features["gf"] # gallery中各图片的features
gl = features["gl"] # gallery中各图片的labels

# query与gallery中各特征相乘,scores指q与g两者的相似度
scores = qf.mm(gf.t())
print(f"scores = {scores}")
# 对于每个query选取最大(最相似)的gallery
res = scores.topk(5, dim=1)[1][:, 0]
print(f"res = {res}")
# 把对应的下标借助labels对比,label相同则说明正确
top1correct = gl[res].eq(ql).sum().item()
print(f"gl[res] = {gl[res]}")
print(f"ql = {ql}")

print("Acc top1:{:.3f}".format(top1correct / ql.size(0)))
